Component({
    /**
     * 组件的属性列表
     */
    properties: {
        like: {
            type: Boolean,  // 必填
        },
        count: {
            type: Number
        },
        readOnly: {         // 只读：如果为true不能点击
            type: Boolean
        }
    },
    /**
     * 组件的初始数据
     */
    data: {
        like: false,
        count: 99,
        yesSrc: 'images/like.png',
        noSrc: 'images/like@dis.png'
    },
    /**
     * 组件的方法列表
     */
    methods: {
        onLike: function (event) {
            if(this.properties.readOnly){
                return
            }

            let like = this.properties.like
            let count = this.properties.count

            count = like ? count - 1 : count + 1
            // 更新properties里的count
            this.setData({
                count: count,
                like: !like
            })

            // 自定义事件（让父级组件可以回调）
            // 激活
            let behavior = this.properties.like ? 'like' : 'cancel'
            this.triggerEvent('like', {
                behavior: behavior
            }, {})
        }
    }
})